<template>
  <el-form
    ref="ruleFormRef"
    style="max-width: 600px"
    :model="ruleForm"
    :rules="rules"
    label-width="auto"
  >
    <el-form-item label="username" prop="username">
      <el-input v-model="ruleForm.username" type="username"/>
    </el-form-item>
    <el-form-item label="password" prop="password">
      <el-input v-model="ruleForm.password" type="password"/>
    </el-form-item>
    <el-form-item label="text" prop="text">
      <el-input v-model="ruleForm.text"/>
      <button @click="bb">dddd</button>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        Create
      </el-button>
      <!-- <el-button @click="resetForm(ruleFormRef)">Reset</el-button> -->
    </el-form-item>
  </el-form>
  
</template>

<script setup>
import { reactive, ref } from 'vue'
import respront from '@/respront/respront'
import { ElMessage } from 'element-plus'

const ruleFormRef = ref()
const ruleForm = reactive({
  username: '',
  password: '',
  text:'',
})
let text=ref('')


const rules = reactive({
  username: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 5, max: 12, message: 'Length should be 5 to 12', trigger: 'blur' },
  ],
  password: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 5, max: 8, message: 'Length should be 5 to 8', trigger: 'blur' },
  ],
  text: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
    { min: 5, max: 8, message: 'Length should be 5 to 8', trigger: 'blur' },
  ],
})
const submitForm = async (formEl) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log(ruleForm.username,ruleForm.password,ruleForm.text)
      respront('/login',ruleForm).then(res=>{
        console.log(res);
        
        if(res.data.code==10000){
            ElMessage({
    message: 'Warning, this is a warning message.',
    type: 'warning',
  })
        }else{
            ElMessage.error('Oops, this is a error message.')
        }
      })
    } else {
      console.log('error submit!', fields)
      ElMessage.error('Oops, this is a error message.')
    }
  })
}
const bb=()=>{
    text.value=Math.floor()(Math.random()*1000000)
}

</script>

<style lang="scss" scoped>

</style>